<table id="company_newsInfo_data"></table>
<script>
$(function(){
	//$.post("../newsInfoServlet",{"getCompanyNewsInfo"})
	$('#company_newsInfo_data').datagrid({   
	    url:'../newsInfoServlet',
	    queryParams:{op:"getCompanyNewsInfo"},
	    loadMsg:'数据加载中...',
	    pagination:true,
	    rownumbers:true,
	    fitColumns:true,
	  	sortName:'nlid',
	  	sortOrder:'desc',
	  	remoteSort:false,
	    striped:true,
	    pageNumber:1,
	    pageSize:10, 
		pageList:[10,20,30,40,50],
	    columns:[[   
	    	{field:'text1',title:'',checkbox:true,width:100,align:'center'}, 
	        {field:'nlid',title:'新闻编号',width:100,align:'center',sortable:true},
	        {field:'nltype',title:'新闻类型',width:100,align:'center'},    
	        {field:'nltitle',title:'新闻标题',width:100,align:'center'},   
	        {field:'nldate',title:'新闻发布的日期',width:100,align:'center'},
	        {field:'_operate',title:'新闻内容',width:100,align:'center',formatter:function(value,rowData,index){
	        	return "<a class='icon-file icon-padding' href=\"javascript:showNewsDetails('"+value+"')\">详细</a>";
	        }},
	    ]],   
	    
	    toolbar: [{
	    	text:'添加',
			iconCls: 'icon-add',
			handler: function(){
				$("#company_newsInfo_data_add").dialog("open");
			}
		},'-',{
			text:'删除',
			iconCls: 'icon-remove',
			handler: function(){
				//获取所有被选中的行
				var rows=$("#company_newsInfo_data").datagrid("getChecked");
				if(rows.length<=0){  //说明没有选中
					$.messager.show({
						title:'温馨提示',
						msg:'请选择您要删除的数据...',
						timeout:2000,
						showType:'slide'
					});
				}else{
					$.messager.confirm('信息确认', '您确定要删除选中的信息吗？', function(r){
						if (r){
							var nlids="";
							//获取所有选中的数据的id
							for(var i=0;i<rows.length-1;i++){
								nlids+=rows[i].nlid+",";
							}
							nlids+=rows[i].nlid;
							
							//向服务器发送请求
							$.post("../newsInfoServlet?t="+new Date(),{op:"delNewsInfo",nlids:nlids},function(data){
								data=parseInt( $.trim(data) );
								if(data>0){
								$.messager.show({
									title:'成功提示',
									msg:'新闻信息删除成功...',
									timeout:3000,
									showType:'slide'
								});
								$("#company_newsInfo_data").datagrid("reload");
								}else{
									$.messager.alert('失败提示','管理员信息删除失败，请稍后再试...','error');
								}
							});
						}
					});
				}
			}
		},'-',{
			text:'修改',
			iconCls: 'icon-edit',
			handler: function(){
				var rows=$("#company_newsInfo_data").datagrid("getChecked");
				if(rows.length<=0){
					$.messager.show({
						title:'温馨提示',
						msg:'请选择您要修改的数据...',
						timeout:2000,
						showType:'slide'
					});
				}else{
					$("#company_newsInfo_data_update").dialog("open");
					
					$("#company_newsInfo_nltitle_update").val( rows[0].nltitle );
					$("#company_newsInfo_nlcontents_update").val( rows[0].nlcontents );
					$("#company_newsInfo_nlimg_update").val( rows[0].nlimg );
					$("#company_newsInfo_nlimgName_update").val( rows[0].nlimgName );
					$("#company_newsInfo_nldate_update").val( rows[0].nldate );
				}
			}
		}]
	});  
	$("#company_newsInfo_data").datagrid('getPager').pagination({
		beforePageText:'第',
		afterPageText:'页 共{pages}页',
		displayMsg:'当前显示{from}-{to} 条记录 共{total} 条记录'
	})
})





//修改公司新闻
function updateCompanyNews(){
	
	var nltype="公司新闻";
	var nltitle=$.trim( $("#company_newsInfo_nltitle_update").val() );
	var nlimgName=$.trim( $("#company_newsInfo_nlimgName_update").val() );
	var nlcontents=ue.getContent();
	var nlimg=$.trim( $("#company_newsInfo_nlimg_update").val() );
	var nldate=$("#company_newsInfo_nldate_update").datebox('getValue');
	
	$.post("../newsInfoServlet?t="+new Date(),{op:"updateNewsInfo",nltype:nltype,nltitle:nltitle,nlimgName:nlimgName,nlcontents:nlcontents,nlimg:nlimg,nldate:nldate},function(data){
		data=parseInt( $.trim(data) );
		console.info(data);
		if(data>0){
			$.messager.show({
					title:'成功提示',
					msg:'公司新闻信息修改成功...',
					timeout:3000,
					showType:'slide'
				});
				$("#company_newsInfo_nltitle_update").val("");
				$("#company_newsInfo_nlimgName_update").val("");
				$("#company_newsInfo_nlcontents_update").val("");
				$("#company_newsInfo_nlimg_update").val("");
				$("#company_newsInfo_nldate_update").val("");
				$("#company_newsInfo_data_update").dialog("close"); //关闭添加对话框
				$("#company_newsInfo_data").datagrid("reload");
		}else{
			$.messager.alert('失败提示','管理员信息修改失败，请稍后再说...','error')
		}
	});
}

//显示新闻内容
function showNewsDetails(){
	var rows=$("#company_newsInfo_data").datagrid("getChecked");
	$("#company_newsInfo_caozuo").dialog("open");
	$("#news_content").val(rows[0].nlcontents);
	

}
</script>


<div id="company_newsInfo_data_add" class="easyui-dialog" title="添加新闻信息" style="width:700px;height:600px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
    <br/>  <br/> 
    
    	 <form action="" style="padding-left:20px;float:left;">
    			<label for="company_newsInfo_nltitle_add">新闻标题：</label><input type="label" name="nltitle" id="company_newsInfo_nltitle_add" required style="width:200px" />  <br/>  <br/> 
   		    	<label for="company_newsInfo_nlimgName_add">新闻图片的名字：</label><input type="label" name="nlimgName" id="company_newsInfo_nlimgName_add" required style="width:200px" />  <br/>  <br/> 
   		    	<label for="company_newsInfo_nlcontents_add">新闻的内容：
   		    	<div >
    				<script id="editor" type="text/plain" style="width:600px;height:200px;"></script>
    			</div> <br/> 
   		    	<label for="company_newsInfo_nlimg_add">新闻的图片：</label><input type="file" name="nlimg" id="company_newsInfo_nlimg_add"  multiple="multiple" onchange="previewMultipleImage(this,'companyNews_show_pic')" required style="width:200px" />  <br/>  <br/> 
   		    	<label for="company_newsInfo_nldate_add">新闻上传日期：</label><input  name="nldate" id="company_newsInfo_nldate_add" class="easyui-datebox" required style="width:200px"  />  <br/>  <br/> 
   				<a href="javascript:addCompanyNews()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">添加</a>		
   				
   		</form><br/> 
   		<div id="companyNews_show_pic" style="width:600px;height:200px;border:1px solid #ef6819;margin-right:10px;">
  
   		</div><br/><br/>
   				
    
</div>  

<div id="company_newsInfo_data_update" class="easyui-dialog"
	title="添加新闻信息"
	style="width:650px;height:600px;border:1px solid #ef6819;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<br /> <br />
	<center>
		<form action="" style="padding-left:20px;float:left;">
			<label for="company_newsInfo_nltitle_update">新闻标题：</label><input
				type="label" name="nltitle" id="company_newsInfo_nltitle_update"
				required style="width:200px" /> <br /> <br /> <label
				for="company_newsInfo_nlimgName_update">新闻图片的名字：</label><input
				type="label" name="nlimgName" id="company_newsInfo_nlimgName_update"
				required style="width:200px" /> <br /> <br /> <label
				for="company_newsInfo_nlcontents_update">新闻的内容：</label><input
				type="label" name="nlcontents"
				id="company_newsInfo_nlcontents_update" required style="width:200px" />
			<br /> <br /> <label for="company_newsInfo_nlimg_update">新闻的图片：</label><input
				type="file" name="nlimg" id="company_newsInfo_nlimg_update"
				multiple="multiple"
				onchange="previewMultipleImage(this,'companyNews_show_pic')"
				required style="width:200px" /> <br /> <br /> <label
				for="company_newsInfo_nldate_update">新闻上传日期：</label><input
				name="nldate" id="company_newsInfo_nldate_update"
				class="easyui-datebox" required style="width:200px" /> <br /> <br />
			<input type="button" onclick="updateCompanyNews()" value="保存" />
		</form>

	</center>
</div>
<script>
	var ue = UE.getEditor('editor');
    function addCompanyNews(){
   	    
    	var nltype="公司新闻";
		var nltitle=$.trim( $("#company_newsInfo_nltitle_add").val() );
		var nlcontents=ue.getContent();
		var nlimgName=$.trim( $("#company_newsInfo_nlimgName_add").val() );
		var nldate=$("#company_newsInfo_nldate_add").datebox('getValue');
    	
    	console.info(nltype);
    	console.info(nltitle);
    	console.info(nlimgName);
    	console.info(nlcontents);
    	console.info(nldate);
    		$.ajaxFileUpload({
    		url:"../newsInfoServlet?op=addNewsInfo",
    		secureuri:false,
    		fileElementId:"company_newsInfo_nlimg_add",
    		dataType:"json",
    		data:{"nltype":nltype,"nltitle":nltitle,"nlimgName":nlimgName,"nlcontents":nlcontents,"nldate":nldate},
    		success:function(data,status){
    			if(parseInt($.trim(data))==1){
    				$.messager.show({
    					title:'成功提示',
						msg:'公司新闻传成功...',
						timeout:2000,
						showType:'slide'
    				});
    				$("#company_newsInfo_data_add").dialog("close");
    				$("#company_newsInfo_data").datagrid("reload");
    			}else{
    				$.messager.alert('失败提示','公司新闻添加失败，请稍后再试...','error');
    			}
    		},
    		error:function(data,status,e){
    			$.messager.alert('失败提示','公司新闻添加失败，请稍后再试...','error');
    		}
    	});
    }

</script>
<!-- 新闻详细信息 -->
<div id="company_newsInfo_caozuo" class="easyui-dialog" title="添加新闻信息" style="width:400px;height:600px;" data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">  
    <br/>  <br/> <center>
    	 <form action="" style="padding-left:20px;float:left;">
    			
   		    	<label for="news_content">新闻的内容： <br/>  <br/>
   		    	<textarea rows="20" cols="40" id="news_content"> </textarea>
   				
   		</form><br/> 
   		</center>
</div>  



